package ltd.dujiabao.dex.core;

import java.util.concurrent.TimeUnit;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author : DuJiabao
 * @Project : delay-executor
 * @Time : 2024/3/19 22:13
 * @Desc :
 */
@Data
@Accessors(chain = true)
public class DelayJobEntity {

    private String className;

    private String jobName;

    private long delayTime;

    private TimeUnit timeUnit;

    private ExecutorType executorType;

    private Class<?> implementation;

    public DelayJobEntity() {
    }

    public DelayJobEntity(String jobName, long delayTime, TimeUnit timeUnit, ExecutorType executorType, Class<?> implementation) {
        this.jobName = jobName;
        this.delayTime = delayTime;
        this.timeUnit = timeUnit;
        this.executorType = executorType;
        this.implementation = implementation;
    }

    public String identity() {
        return jobName + "." + timeUnit.toMillis(delayTime);
    }

    public long delayTimeInSec() {
        return timeUnit.toSeconds(delayTime);
    }
}
